package com.example.module.favorites.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.module.favorites.DO.GetFavoritesDO;
import com.example.module.favorites.form.FavoritesAddForm;
import com.example.module.favorites.form.FavoritesDeleteForm;
import com.example.module.favorites.form.GetFavoritesForm;
import com.example.module.favorites.vo.GetFavoritesVO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.module.favorites.service.FavoritesService;

import java.util.List;

/**
 * @author ghy
 * @date 2025/08/15
 * @description 收藏夹控制层
 */
@Validated
@RestController
@RequestMapping("/favorites")
public class FavoriteController {
    @Resource
    private FavoritesService FavoritesService;

    /*
     * 添加收藏
     *
     * @param favoritesAddForm
     * @return void
     * */
    @PostMapping("/add")
    @SaCheckLogin
    public void addFavorites(@RequestBody FavoritesAddForm favoritesAddForm) {
        FavoritesService.addFavorites(favoritesAddForm);
    }

    /*
     * 删除收藏
     *
     * @param favoritesDeleteForm
     * @return void
     * */
    @PostMapping("/delete")
    @SaCheckLogin
    public void deleteFavorites(@RequestBody FavoritesDeleteForm favoritesDeleteForm) {
        FavoritesService.deleteFavorites(favoritesDeleteForm);
    }

    /*
     * 查询收藏
     *
     * @param GetFavoritesForm
     * @return List<GetFavoritesDO>
     * */
    @PostMapping("/get")
    @SaCheckLogin
    public List<GetFavoritesVO> getFavorites(@RequestBody GetFavoritesForm getFavoritesForm) {
        return FavoritesService.getFavorites(getFavoritesForm);
    }

    /*
     * 分页查询收藏
     *
     * @param getFavoritesForm 查询条件
     * @return Page<GetFavoritesVO> 分页结果
     */
    @PostMapping("/page")
    @SaCheckLogin
    public Page<GetFavoritesVO> getFavoritesPage(@RequestBody GetFavoritesForm getFavoritesForm) {
        return FavoritesService.getFavoritesPage(getFavoritesForm);
    }


}
